<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class TaskTest_statu
{
    protected $id;
    protected $type;

    public function __construct($id, $type)
    {
        $this->id = $id;
        $this->type = $type;
    }

    protected function script()
    {
        return <<<JS
        $('.grid-check-row').on('click', function () {
            var id = $(this).data('id');
            var type = $(this).data('type');
    // Your code.
            $.ajax({
                url: '/admin/taskTest/opreat',
                data: {
                    _token:LA.token,
                    id: id,
                    type: type
                },
                type: 'post',
                dataType: 'json',
                success:function(ret){
                    $.pjax.reload('#pjax-container');
                    toastr.success('操作成功 !');
                },
                error: function(ret){
                    console.log(ret);
                }
            })
            return false;
        
        });
JS;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "<a href='javascript:void(0);' class='grid-check-row' data-id='{$this->id}' data-type='{$this->type}'>".($this->type==1?'显示':'隐藏')."</a>&nbsp;&nbsp;";
    }

    public function __toString()
    {
        return $this->render();
    }

}

